package com.ruoyi.content.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.content.domain.Tag;
import com.ruoyi.content.service.ITagService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 内容标签 信息操作处理
 * 
 * @author cloudoer
 * @date 2019-06-21
 */
@Controller
@RequestMapping("/content/tag")
public class TagController extends BaseController
{
    private String prefix = "content/tag";
	
	@Autowired
	private ITagService tagService;
	
	@RequiresPermissions("content:tag:view")
	@GetMapping()
	public String tag()
	{
	    return prefix + "/tag";
	}
	
	/**
	 * 查询内容标签列表
	 */
	@RequiresPermissions("content:tag:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Tag tag)
	{
		startPage();
        List<Tag> list = tagService.selectTagList(tag);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出内容标签列表
	 */
	@RequiresPermissions("content:tag:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Tag tag)
    {
    	List<Tag> list = tagService.selectTagList(tag);
        ExcelUtil<Tag> util = new ExcelUtil<Tag>(Tag.class);
        return util.exportExcel(list, "tag");
    }
	
	/**
	 * 新增内容标签
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存内容标签
	 */
	@RequiresPermissions("content:tag:add")
	@Log(title = "内容标签", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Tag tag)
	{		
		return toAjax(tagService.insertTag(tag));
	}

	/**
	 * 修改内容标签
	 */
	@GetMapping("/edit/{tagId}")
	public String edit(@PathVariable("tagId") Long tagId, ModelMap mmap)
	{
		Tag tag = tagService.selectTagById(tagId);
		mmap.put("tag", tag);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存内容标签
	 */
	@RequiresPermissions("content:tag:edit")
	@Log(title = "内容标签", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Tag tag)
	{		
		return toAjax(tagService.updateTag(tag));
	}
	
	/**
	 * 删除内容标签
	 */
	@RequiresPermissions("content:tag:remove")
	@Log(title = "内容标签", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(tagService.deleteTagByIds(ids));
	}
	
}
